#ifndef StringGridView_First
#define StringGridView_First
#ifdef __GNUG__
#pragma interface
#endif

#include "GridView.h"
#include "Fields.h"

class CellEditField;
class TextViewOverlay;

//--- StringGridView -----------------------------------------------------------

class StringGridView: public GridView {
public:
	MetaDef(StringGridView);

	StringGridView(EvtHandler *eh, bool cache= TRUE);
	~StringGridView();

	bool IsEditable(const Point &cell);
	virtual bool SetEditCell(const Point &cell);
	TextViewOverlay *GetTextViewOverlay();

	virtual const char *GetString(const Point &cell, bool fordrawing);
	virtual bool SetString(const Point &cell, const char *s);
	virtual void TabField(const Point &cell, const Token &t);
	virtual Point CalculateTab(const Point &curr, const Region &r, bool fwd= TRUE);

protected:
	Metric CellSize(const Point &cell);
	void DrawCell(const Point &cell, const Rectangle&, const Rectangle&, bool);
	void SetExtent(Point);
	void SetOrigin(Point);

	Command *DispatchEvents(Point lp, Token &t, Clipper *vf);

protected:
	CellEditField *tf;
};

inline bool StringGridView::IsEditable(const Point &cell)
	{ return GetString(cell, FALSE) != 0; }

//---- CellEditField -----------------------------------------------------------

class CellEditField: public EditField {
public:
    StringGridView *sgridview;
    Point editcell;
public:
    MetaDef(CellEditField);
    CellEditField(StringGridView *sgv, int minwidth, Font *f= gSysFont);
    bool ValidateString(const char *s);
    const char *GetStringForEditing();
    void SetEditCell(const Point &ec);
    Command *Input(Point lp, Token &t, Clipper *vf);
		Command *InsertString(const char *s);
};

#endif

